﻿#include <msp430x42x.h>
//#include "io.h"
#include "basictimer.h"
void Basictimer::open(){
   IE2 |= BTIE;                      // Enable basictimer Timer interrupt 
  _EINT();
}

Basictimer::Basictimer(int Div_Sec)
{       int div,bits=0;
        div=Div_Sec;
        bits++;
        while(div>1){       //将任意给定的参数变换为可选项之一
          div>>=1;
          bits++;
        }
        while(bits--){
          div<<=1;
        }
	switch(div)
  {
     case 20: BTCTL = BTDIV+BT_fCLK2_DIV256;break; // 2s BT Int 
     case 1:  BTCTL = BTDIV+BT_fCLK2_DIV128;break; // 1s BT Int 
     case 2:  BTCTL = BTDIV+BT_fCLK2_DIV64;break;  //  1/2s BT Int  
     case 4:  BTCTL = BTDIV+BT_fCLK2_DIV32;break;  //  1/4s BT Int      
     case 8:  BTCTL = BTDIV+BT_fCLK2_DIV16;break;  //  1/8s BT Int  
     case 16: BTCTL = BTDIV+BT_fCLK2_DIV8;break;   //  1/16s BT Int  
     case 32: BTCTL = BTDIV+BT_fCLK2_DIV4;break;   //  1/32s BT Int  
     case 64: BTCTL = BTDIV+BT_fCLK2_DIV2;break;   //  1/64s BT Int 
     case 128:BTCTL = BT_fCLK2_DIV256;break;       //  1/128s BT Int 
     case 256:BTCTL = BT_fCLK2_DIV128;break;       //  1/256s BT Int 
     case 512:BTCTL = BT_fCLK2_DIV64;break;        //  1/512s BT Int 
     case 1024:BTCTL = BT_fCLK2_DIV32;break;       //  1/1024s BT Int 
     case 2048:BTCTL = BT_fCLK2_DIV16;break;       //  1/2048s BT Int 
     case 4096:BTCTL = BT_fCLK2_DIV8;break;        //  1/4096s BT Int 
     case 8192:BTCTL = BT_fCLK2_DIV4;break;        //  1/8192s BT Int  
     case 16384:BTCTL =BT_fCLK2_DIV2;break;        // 1/16384s BT Int 
     default :;
  }

}


void Basictimer::close()
{
	IE2 &= ~BTIE;	
}
#pragma vector=BASICTIMER_VECTOR
__interrupt void basic_timer()
{

}

